package ant;


import org.jbox2d.dynamics.Body;

import ant.properties.ADN;

import com.unicate.DrawObject;



import world.*;

public class WOAObject {

	public Integer id = 0;
	public Position pos;
	public Body myBody;
	public float direction = 0; 
	



	public AntWorld world;	
	public String type;
	public ADN adn;
	
	/**
	 * @param w : the Antworld attached to the object
	 * @param pos : object's position
	 *  
	 */	
	public WOAObject(AntWorld w, Position pos) {
		super();
		world = w;
		adn = new ADN();
		this.pos = pos;
		this.id = w.woal.get_new_id();
		w.woal.add_o(this);
	}
	
	/**
	 * @return the type 
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}
	
	
	
	/**
	 * @param position to move
	 * 
	 */
	public void move(Position to)
	{		
		this.setPos(to);
		this.myBody.setXForm(to.getVec2(), 0);	
	}
	
	/**
	 * @return the physical body element
	 */
	public Body getMyBody() {
		return myBody;
	}
	/**
	 * @param myBody : set the physical body
	 */
	public void setMyBody(Body myBody) {
		this.myBody = myBody;
	}

	/**
	 * @param pos : set the pos
	 */
	public void setPos(Position pos) {
		this.pos = pos;
	}
	
	/**
	 * @return the drawObject of the WOAObject
	 */
	public DrawObject getDrawObject()
	{
		DrawObject dobj = new DrawObject(this.id, getPos(), this.type);
		dobj.size = adn.getCurrent("size");
		dobj.direction = direction;
		return dobj;
	}
	
	/**
	 * @return the position
	 */
	public Position getPos() {
		return new Position(pos._map, myBody.getPosition().x, myBody.getPosition().y);
	}
	

	protected void finalize() throws Throwable
	{
	  world.woal.remove_o(id);
	  //do finalization here
	  super.finalize(); //not necessary if extending Object.
	} 
	
}
